package com.zto.sch.base.normal;

import com.google.common.collect.ArrayListMultimap;
import com.google.common.collect.ImmutableListMultimap;
import com.google.common.collect.Multimap;
import com.google.common.collect.Multimaps;
import com.zto.sch.base.normal.domain.User;
import org.junit.Test;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @program: sch-diy-parent
 * @description:
 * @author: sch
 * @create: 2021-05-31 03:23
 **/
public class MapTest {
    @Test
    public void test1(){
        Map<String, String> mapAll = new HashMap<>();
        mapAll.put("name1", "xiaoqiang1");
        Map<String, String> map1 = new HashMap<>();
        map1.put("name2","xiaoming2");
        mapAll.putAll(map1);
        System.out.println(mapAll);
    }

    @Test
    public void test2(){
        Multimap<String, String> machineDataIdMultiMap = ArrayListMultimap.create();
        machineDataIdMultiMap.put("a","a1");
        machineDataIdMultiMap.put("a","a2");
        machineDataIdMultiMap.put("a","a3");

        machineDataIdMultiMap.put("b","b1");
        machineDataIdMultiMap.put("b","b2");
        machineDataIdMultiMap.put("b","b3");

        System.out.println(machineDataIdMultiMap);
        System.out.println(machineDataIdMultiMap.asMap());


    }

    @Test
    public void testMultimapsIndex(){
        List<User> list = new ArrayList<>();
        list.add(new User(1L,"1L"));
        list.add(new User(111L,"1L"));
        list.add(new User(2L,"2L"));
        list.add(new User(22L,"2L"));
        ImmutableListMultimap<Long, User> index = Multimaps.index(list, User::getId);
        System.out.println(index.asMap());
    }
}
